// 获取文书
import request from "@/utils/request";
import { pa } from "element-plus/es/locales.mjs";
// http://110.191.238.10:19638/WeatherForecast/GetDocData/222/123/2012-01-01

// 获取日期相关数据
export const GetJIAOBAN_1 = (data) =>
  request({
    method: "get",
    url: `/icu/getReport?date=${data}`,
  });

// 保存信息
export const GetJIAOBAN_2 = (data) =>
  request({
    method: "get",
    url: `/icu/getReport/2?date=${data}`,
  });

export const getEcmoReport = (data) =>
  request({
    method: "get",
    url: `/icu/getEcmoReport?docId=${data}`,
  });

// 获取凉山州第一人民医院ICU疾病统计
export const getDiseaseAPI = (data) =>
  request({
    method: "get",
    // url: "/icu/getSeekCountDate?startDay=2025-02-01&endDay=2025-02-10",
    url: `/icu/getSeekCountDate?startDay=${data[0]}&endDay=${data[1]}`,
  });

export const getBloodAPI = (data) =>
  request({
    method: "get",
    url: `/icu/getBloodReport?docId=${data}`,
  });

// 上传
export const upload = (data) => {
  console.log("上传数据:", data);
  console.log(
    "文件类型:",
    data.file instanceof Blob ? "Blob" : typeof data.file
  );

  // 创建 FormData 对象
  const formData = new FormData();

  // 检查文件是否为 Blob 类型
  if (data.file instanceof Blob) {
    // 添加文件流（Blob对象）
    formData.append("file", data.file, "blood-report.pdf");
  } else if (data.file instanceof File) {
    // 如果是 File 对象也正常处理
    formData.append("file", data.file, "blood-report.pdf");
  } else {
    // 如果是其他类型，尝试转换（适用于某些特殊情况）
    console.error("传入的文件不是有效的 Blob 或 File 对象");
    throw new Error("无效的文件格式");
  }

  // 添加 docId 参数
  // formData.append('docId', data.docId);

  // 发送请求
  return request({
    method: "post",
    url: `http://192.168.0.72:8091/icu/upload?docId=${data.docId}`,
    data: formData,
    // 注意：不要手动设置 Content-Type，让浏览器自动设置 multipart/form-data 和边界
  });
};

export const getApacheAPI = (data) =>
  request({
    method: "get",
    url: `/icu/getApacheReport?startDay=${data.startDay}&endDay=${data.endDay}`,
  });

export const getApacheTotal = (params) =>
  request({
    method: "get",
    url: `/icu/getApacheTotal?date=${params.date}-01 00:00:00`,
  });

export const uploadAPI = (formData, docId) =>
  request({
    method: "post",
    url: `http://192.168.0.72:8091/icu/upload?docId=${docId}`,
    data: formData,
    // 注意：不要手动设置 Content-Type，让浏览器自动设置 multipart/form-data 和边界
  });

export const getQuery = (data) =>
  request({
    method: "post",
    url: `/icu/getQuery`,
    data
  });
